import { errorReport, getUserId } from '@/utils';
import fl from '@king-fisher/falcon';
import { Request } from '@/types/api.d';

// 目前只有ios请求会带上cookie
export function getPlRequest({ url, data, method = 'GET', headers, dataType = 'json' }: Request) {
  return new Promise((resolve, reject) => {
    fl.request({
      url,
      data,
      method,
      header: {
        ...headers,
      },
      dataType,
      success: (res: unknown) => {
        resolve(res);
      },
      fail: (error: Error) => {
        errorReport({
          name: '接口请求错误',
          message: `出错接口的url:${url},用户的userid:${getUserId()}`,
          stock: error?.stock,
        });
        reject(error);
      },
    });
  });
}
